package com.fenxiangle.yueding.feature.order.view.adapter;

import android.graphics.Color;
import android.text.Html;
import android.text.TextUtils;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fenxiangle.yueding.R;
import com.fenxiangle.yueding.common.util.DateTool;
import com.fenxiangle.yueding.entity.OrderType;
import com.fenxiangle.yueding.entity.bo.PublishDemandBo;
import com.fenxiangle.yueding.entity.bo.ReceviedState;
import com.suozhang.framework.framework.AM;

public class OrderAdapter extends BaseQuickAdapter<PublishDemandBo, BaseViewHolder> {
    public OrderAdapter() {
        super(R.layout.item_order);
    }
    //指示器设置渐变色

    @Override
    protected void convert(BaseViewHolder helper, PublishDemandBo item) {
        AM.image().bindToCircleObject(item.getUserHead(), helper.getView(R.id.iv_my_publish_head));
        AM.image().bindToCircleObject(item.getOwnUserHead(), helper.getView(R.id.iv_my_head));
        helper.setText(R.id.tv_my_publish_title, Html.fromHtml("<b><tt>邀约内容：</tt></b>" +"人数" +item.getNumPeople() + "人。 " + item.getOrderDescribe()))
                .setText(R.id.tv_my_publish_date, "时间：" + DateTool.formatTime2(item.getStartTime()) + "——" + DateTool.formatTime2(item.getEndTime()))
                .setText(R.id.tv_my_publish_address, "地点：" + item.getAgreedPlace())
                .setText(R.id.tv_my_publish_username, item.getUserName())
                .setText(R.id.tv_my_publish_credit, "信用金：￥100")
                .setText(R.id.tv_my_publish_stauts, item.getOrderStatus() == 6 ?
                        Html.fromHtml("" + (item.getType() == 1 ? "抢单" : "邀约单") + "--<font color='#ffa458'><b><tt>" + OrderType.getName(item.getOrderStatus()) + "</tt></b></font>") :
                        Html.fromHtml("" + (item.getType() == 1 ? "抢单" : "邀约单") + "--<font color='#6e6e6e'>" + OrderType.getName(item.getOrderStatus()) + "</font>"))
                .setText(R.id.tv_my_publish_money, "服务费：￥" + item.getUnitPrice())
                .setText(R.id.tv_my_publish_order_no, "订单号：" + item.getOrderId())
                .setText(R.id.btn_state, ReceviedState.getName(item.getOrderStatus()))
                .addOnClickListener(R.id.btn_call_phone)
                .addOnClickListener(R.id.btn_copy_wx)
                .addOnClickListener(R.id.iv_my_publish_head)
                .addOnClickListener(R.id.tv_my_publish_username)
                .addOnClickListener(R.id.btn_state);

        if (TextUtils.isEmpty(ReceviedState.getName(item.getOrderStatus()))) {
            helper.getView(R.id.btn_state).setVisibility(View.GONE);
        } else {
            helper.getView(R.id.btn_state).setVisibility(View.VISIBLE);
        }


        if (item.getOrderStatus() == -1 || item.getOrderStatus() == 0 || item.getOrderStatus() == 2) {
            helper.getView(R.id.btn_copy_wx).setVisibility(View.GONE);
            helper.getView(R.id.btn_call_phone).setVisibility(View.GONE);
            helper.getView(R.id.iv_my_head).setVisibility(View.GONE);
        } else {
            helper.getView(R.id.btn_copy_wx).setVisibility(View.VISIBLE);
            helper.getView(R.id.btn_call_phone).setVisibility(View.VISIBLE);
            helper.getView(R.id.iv_my_head).setVisibility(View.VISIBLE);
        }
    }
}
